<template>

<el-container class="home-container">
    <!-- 头部 -->
    <el-header>
        <div>
            <span>云医院his系统</span>
        </div>
        <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 主体容器 -->
    <el-container>
        <!-- 侧边栏 -->
        <el-aside :width="isCollapse ? '64px' : '200px'">
            <!-- 折叠效果 -->
            <div class="toggle-btn" @click="toggleCollapse()">
                <el-button type="info" :class="icons.istoggleIcon" v-show="istoggleIcon" ></el-button>
                <el-button type="info" :class="icons.nottoggleIcon" v-show="!istoggleIcon" ></el-button>
            </div>
            <!-- 侧边栏菜单 -->
            <el-menu
                background-color="#606266"
                text-color="#fff"
                active-text-color="#409fff" unique-opened :collapse="isCollapse" :collapse-transition="false" router :default-active="activePath"> <!-- :default-active="activePath"-->
        <!-- 一级菜单 -->
        <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
            <template slot="title">
            <i :class="icons[item.id]" style="color:#f4f4f4"></i>
            <span>{{item.authName}}</span>
            </template>
        <!-- 二级菜单 -->
        <el-menu-item :index="subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="navState(subItem.path)" >
            <!-- 二级菜单的模板 -->
            <template slot="title">
            <i class="el-icon-menu"></i>
            <span>{{subItem.authName}}</span>
            </template>
        </el-menu-item>
      </el-submenu>
    </el-menu>
        </el-aside>
        <!-- 主体 -->
        <el-main>
            <!-- 这是一个路由点位符 -->
            <router-view></router-view>
        </el-main>
    </el-container>
</el-container>

</template>
<script>
    export default {
        data() {
            return {
                //左侧菜单的数据
                menuList: [
                    {id:"I1",authName:"挂号收费",
                        children:[
                            {
                                id:"1-1",
                                authName:"现场挂号",
                                path:"/1-1"
                            },
                             {
                                id:"1-2",
                                authName:"退号",
                                path:"/1-2"
                            },
                        ]
                    },
                    {id:"I2",authName:"门诊医生",
                         children:[
                            {
                                id:"2-1",
                                authName:"看诊",
                                path:"/2-1"
                            },
                            {
                                id:"2-2",
                                authName:"医技模板",
                                path:"/2-2"
                            },
                            {
                                id:"2-3",
                                authName:"西药处方模板",
                                path:"/2-3"
                            },
                        ]
                    },
                    {id:"I3",authName:"系统信息",
                       children:[
                            {
                                id:"3-1",
                                authName:"常数类别管理",
                                path:"/3-1"
                            },
                            {
                                id:"3-2",
                                authName:"科室管理",
                                path:"/3-2"
                            },
                            {
                                id:"3-3",
                                authName:"用户管理",
                                path:"/user"
                            },
                               {
                                id:"3-4",
                                authName:"挂号级别管理",
                                path:"/3-4"
                            },
                            {
                                id:"3-5",
                                authName:"诊断目录管理",
                                path:"/3-5"
                            },
                            {
                                id:"3-6",
                                authName:"非药收费项目管理",
                                path:"/3-6"
                            },
                            {
                                id:"3-7",
                                authName:"医生排班管理",
                                path:"/3-7"
                            },
                           
                        ]
                    },
                ],
                //图标
                icons: {
                    istoggleIcon:"el-icon-d-arrow-right",
                    nottoggleIcon:"el-icon-d-arrow-right",
                    I1:'el-icon-bell',
                    I2:'el-icon-user',
                    I3:'el-icon-setting',
                    
                },
                //表示不折叠
                isCollapse: false,
                // 菜单折叠图标切换
                activePath: ''
            }
        },
        created() {
            // this.getMenuList()
            //从sessionStorage中获取到activePath并赋值给属性activePath
            this.activePath = window.sessionStorage.getItem('activePath')
        },
        methods: {
            logout() {
                //清除sessionStorage中的数据(token)
                window.sessionStorage.clear();
                this.$router.push('/login')
            },
            // 暂时弃用
            // async getMenuList() {
            //     //需要向后台发送axios请求获取数组
            //     const {
            //         data: res
            //     } = await this.$http.get('menus')
            //     //判断数据是否获取到了
            //     if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
            //     this.menuList = res.data
            //     console.log(res)
            // },
            toggleCollapse() {
                
                //处理菜单的折叠效果
                this.isCollapse = !this.isCollapse
            },
            //链接的激活状态
            navState(path) {
                window.sessionStorage.setItem('activePath', path)
            }
        },
        computed: {
            // 菜单折叠图标切换
            istoggleIcon(){
                return this.isCollapse;
            }
        },
    }
</script>

<style lang="less" scoped>
    .home-container {
        height: 100%;
    }
    .el-header {
        background-color: #303133;
        display: flex;
        justify-content: space-between;
        padding-left: 0;
        align-items: center;
        color: #ffffff;
        font-size: 20px;
        >div {
            display: flex;
            align-items: center;
            span {
                margin-left: 15px;
            }
        }
    }
    .el-aside {
        background-color: #606266;
        .el-menu {
            border-right: none;
        }
    }
    .el-main {
        background-color: #DCDFE6;
    }
    .iconfont {
        margin-right: 12px;
    }
    .toggle-btn {
        background-color: #909399;
        font-size: 10px;
        color: #ffffff;
        letter-spacing: 2px;
        text-align: center;
        line-height: 22px;
        cursor: pointer;
    }
</style>
